﻿using Students.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Students.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            // Create a list of students
            List<StudentModel> _alumni = new List<StudentModel>();
            _alumni.Add(new StudentModel{Name = "Joe", Phone = "555-55-555", HomeTown = "Florida" });
            _alumni.Add(new StudentModel{Name = "Lynda", Phone = "555-33-555", HomeTown = "Germany"});
            _alumni.Add(new StudentModel{Name = "Steve", Phone = "555-22-555", HomeTown = "SLC"});
            // Create ViewModel 
            IndexViewModel vm = new IndexViewModel();
            // set Title
            vm.Title = "Hello Students";
            // set the Studnets list
            vm.Alumni = _alumni;
            // pass the VM to the View
            return View(vm);
        }
        [HttpGet]
        public ActionResult About()
        {
            StudentModel vm = new StudentModel();
            //vm.Title = "Add a new Student";
            ViewBag.Message = "Your application description page.";

            return View(vm);
        }

        [HttpPost]
        public ActionResult About(StudentModel model)
        {

            // Add to singleton array OR do you server (ajax or db) call 
            return RedirectToAction("Index");
        }





        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}